<template>
  <div class="content">
    <BreadNav
      :location="location"
      :routers="routers"
      @getData="getData"
    />
    <LabelList
      v-if="!showDetail"
      :labelList="labelList"
      @getData="getData"
    />
    <main v-if="showDetail">
      <article>
        <ArticleContent />
      </article>
      <aside>
        <AsideLinks />
      </aside>
    </main>
    <Footer />
    <Masks
      ref="childRef"
      :bigPicture="bigPicture"
      :isMask="isMask"
      @changeMaskState="changeMaskState"
    />
  </div>
</template>

<script>
import BreadNav from '@/components/BreadNav.vue'
import Footer from '@/components/Footer.vue'
import LabelList from '@/components/LabelList.vue'
import AsideLinks from '@/components/AsideLinks.vue'
import ArticleContent from '@/components/ArticleContent.vue'
import { getArticleList } from '@/api/article'
import Masks from '@/components/Masks.vue'
import bus from '@/main'
export default {
  components: {
    BreadNav,
    Footer,
    LabelList,
    AsideLinks,
    Masks,
    ArticleContent
  },
  data() {
    return {
      location: '闲言碎语',
      routers: 'xianyansuiyu',
      showDetail: false,
      articleX: {},
      baseURL: this.baseURL,
      imgs: [],
      labelList: [],
      bigPicture: '',
      isMask: false
    }
  },
  computed: {
    images: function () {
      return function (img) {
        return img === '' ? '' : `${this.baseURL}/uploads/${img}`
      }
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    bus.$on('getData', this.getData)
  },
  methods: {
    async getData() {
      if (this.$route.query.id) {
        this.showDetail = true
      } else {
        const opt = {
          page: 1,
          per_page: 100,
          channel_id: 2
        }
        const res = await getArticleList(opt)
        this.labelList = res.data.data
        this.showDetail = false
      }
    },
    large(v) {
      this.bigPicture = v
      this.isMask = true
      this.$refs.childRef.enlarge()
    },
    changeMaskState() {
      this.isMask = false
    },
    previewPicture(e) {
      console.log(e)
      if (e.target.tagName === 'IMG') {
        // this.picturePreview.src = e.target.src;
        // this.picturePreview.visible = true;
        this.bigPicture = e.target.src
        this.isMask = true
        this.$refs.childRef.enlarge()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
// 宽度大于1201px时
@media screen and (min-width: 1201px) {
  .content {
    width: 1200px;
    margin: 0 auto;
  }
}

// 宽度小于1200px时
@media screen and (max-width: 1200px) {
  .content {
    margin: 0 40px;
  }
}

@media only screen and (max-width: 768px) {
  body .content main article {
    width: 100%;
  }
  aside {
    display: none;
  }
}
@media only screen and (max-width: 480px) {
  .content {
    margin: 0 15px;
  }
  body .content main article {
    padding: 20px 10px;
    h1 {
      font-size: 18px;
    }
    p {
      font-size: 13px;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      span {
        margin-right: 10px;
      }
    }
    div {
      ::v-deep p {
        padding: 2px 0;
      }
      ::v-deep li {
        margin-left: 10px;
      }
    }
  }
}
.content {
  main {
    display: flex;
    article {
      width: 860px;
    }
    aside {
      width: 320px;
      margin-left: 20px;
      height: 300px;
      border-radius: 3px;
    }
  }
}
</style>
